package cn.stylefeng.guns.modular.manager.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.manager.entity.FlowUserguide;
import cn.stylefeng.guns.modular.manager.mapper.FlowUserguideMapper;
import cn.stylefeng.guns.modular.manager.model.params.FlowUserguideParam;
import cn.stylefeng.guns.modular.manager.model.result.FlowUserguideResult;
import  cn.stylefeng.guns.modular.manager.service.FlowUserguideService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yumker
 * @since 2021-01-07
 */
@Service
public class FlowUserguideServiceImpl extends ServiceImpl<FlowUserguideMapper, FlowUserguide> implements FlowUserguideService {

    @Override
    public void add(FlowUserguideParam param){
        FlowUserguide entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(FlowUserguideParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(FlowUserguideParam param){
        FlowUserguide oldEntity = getOldEntity(param);
        FlowUserguide newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public FlowUserguideResult findBySpec(FlowUserguideParam param){
        return null;
    }

    @Override
    public List<FlowUserguideResult> findListBySpec(FlowUserguideParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(FlowUserguideParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(FlowUserguideParam param){
        return param.getUserguideId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private FlowUserguide getOldEntity(FlowUserguideParam param) {
        return this.getById(getKey(param));
    }

    private FlowUserguide getEntity(FlowUserguideParam param) {
        FlowUserguide entity = new FlowUserguide();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
